package com.feilong.cn.mybatis.Auto;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by yangxulong on 2018/4/2.
 */
public class AutoMapperProxy implements InvocationHandler {
    private AutoSqlSession session;

    public AutoMapperProxy(AutoSqlSession session) {
        this.session = session;
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String strNameId = TestMapper.class.getName() + ".selectByPrimaryKey";
        if ((method.getDeclaringClass().getName() + "." + method.getName()).equals(strNameId)) {
            String strSql = AutoConfiguration.XMLParser.GetStatemenet(strNameId);
            strSql = strSql.replace("?", args[0].toString());
            return session.SelectOne(strSql);
        } else {
            return method.invoke(this, args);
        }
    }
}
